package com.freewater.parking.domain.blacklist;

import com.freewater.parking.domain.common.DomainEvent;
import com.freewater.parking.domain.common.PlateNumber;
import org.apache.commons.lang3.Validate;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 车牌号从黑名单移除事件
 */
public class RemovedFromBlackListEvent implements DomainEvent {
    /**
     * 车牌号
     */
    private final PlateNumber plateNumber;
    /**
     * 事件时间
     */
    private final LocalDateTime time;

    public RemovedFromBlackListEvent(PlateNumber plateNumber, LocalDateTime time) {
        Validate.notNull(plateNumber, "车牌号不能为空");
        Validate.notNull(time, "车牌号从黑名单移除时间不能为空");
        this.plateNumber = plateNumber;
        this.time = time;
    }

    @Override
    public LocalDateTime occurAt() {
        return this.time;
    }

    /**
     * 获取车牌号
     *
     * @return 车牌号
     */
    public PlateNumber getPlateNumber() {
        return plateNumber;
    }

    /**
     * 获取事件时间
     *
     * @return 事件时间
     */
    public LocalDateTime getTime() {
        return time;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        RemovedFromBlackListEvent that = (RemovedFromBlackListEvent) o;
        return Objects.equals(plateNumber, that.plateNumber) && Objects.equals(time, that.time);
    }

    @Override
    public int hashCode() {
        return Objects.hash(plateNumber, time);
    }
}
